******************************************************************************
*** 		  Replication Data: Marius Mehrl & Abel Escribà-Folch          ***
*** The dictator's legionnaires: foreign recruitment, coups, and uprisings ***
*** 					   Published in Democratization 				   ***
*** 			   Contact: Marius Mehrl, m.mehrl@leeds.ac.uk 			   ***
******************************************************************************

* Insert correct file path
use "C:\...\legions.dta", clear

* Label variables
label variable statenme "Country"
label variable coupattempt "Coup Attempt"
label variable foreignlegion "Foreign Legion"
label variable flcount "Foreign Legion - Count"
label variable leadertransition "Leader Transition"
label variable irregular "Irregular Leader Transition"
label variable v2x_polyarchy "V-Dem Polyarchy"
label variable polity2 "Polity2 score"
label variable xm_qudsest "Unified Democracy Score"
label variable milex_cow "MilEx CoW"
label variable milper "Military personnel CoW"
label variable irst "Iron & Steel prod CoW"
label variable pec "Energy Consumption CoW"
label variable tpop "Population CoW"
label variable upop "Urban Population CoW"
label variable cinc "CINC score CoW"
label variable ucdpongoing "Intrastate Conflict - Incidence"
label variable ucdponset "Intrastate Conflict - Onset"
label variable wbgdp2011est "GDP Ander 2020"
label variable wbpopest "Population Anders 2020"
label variable sdpest "SDP Anders 2020"
label variable wbgdppc2011est "GDP p.c. Anders 2020"
label variable rivalry "Rivalry Count"
label variable draft_binary "Conscription"
label variable latent_personalism "Personalism (GWF latent variable)"
label variable latent_personalism_noparam "Personalism (GWF latent variable EXCLDUING PARAMILITARY INDICATOR)"
label variable egippop "Share Polit Excluded Groups (all Pop.)"
label variable legippop "Share Polit Excluded Groups (polit relevant ethnicities Pop.)"
label variable cntr_relevance "Ethnicity Politically Relevant"
label variable milex_sipri "MilEx SIPRI"
label variable colruler "Colonial Ruler ICOW"


****************************************************
* Last Variable constructions, log transformations *
****************************************************

xtset ccode year

* using CoW milex data to maximize sample
gen ln_milex = ln(milex_cow)
gen ln_pop=ln(wbpopest)
 gen ln_upop=ln(upop+1)

gen coupsuccess=0 if coupattempt!=.
replace coupsuccess=1 if coupattempt==2   
replace  coupattempt=1 if coupattempt==2
 
replace intrastate=0 if intrastate==.
replace intrastate=1 if intrastate>1 & intrastate!=. 
 
gen regimetype=.
replace regimetype=0 if polity2<=6
replace regimetype=1 if polity2>-6 & polity2<6
replace regimetype=2 if polity2>=6 & polity2!=.
gen democ=0 if polity2!=.
replace democ=1 if regime==2
gen anoc=0  if polity2!=.
replace anoc=1 if regime==1

gen ln_gdp_pc=ln(wbgdppc2011est)
gen ln_gdp=ln(wbgdp2011est)

gen diff_lngdppc=D.ln_gdp_pc
replace diff_lngdppc=0 if diff_lngdppc==.
gen diff_lnmilex=D.ln_milex
replace diff_lnmilex=0 if diff_lnmilex==.

* Population under arms
gen militaryshare=milper/tpop

* Colonial Ruler dummies
tab colruler
gen col_uk=0
replace col_uk=1 if colruler==200
gen col_fr=0
replace col_fr=1 if colruler==220

* UCDP duration variable
gen intra_dur=.
replace intra_dur=0 if intrastate==0
replace intra_dur=1 if intrastate==1 & l.intrastate!=1
by ccode: replace intra_dur=intra_dur[_n-1]+1 if intra_dur==.
order intra_dur, after(intrastate)

* Construct Time since last coup attempt / foreign legion use
btscs coupattempt year ccode, gen(att_years)
btscs foreignlegion year ccode, gen(fl_years)

* Construct ONSET version of the foreign legion dummy
gen fl_onset=foreignlegion
replace fl_onset=. if foreignlegion==1 & l.foreignlegion==1
order fl_onset, after(foreignlegion)

* regional coup attempts in previous year
recode ccode(2/165=1) (200/395=2) (402/591=3) (600/698=4) (700/860=5) (900/990=6), gen(region)
replace region=3 if ccode==626

bysort region year: egen reg_coups=total(coupattempt)
sort ccode year

* Democratic Transitions
tab gwf_fail_subsregime
recode gwf_fail_subsregime (2 3=0), gen(gwf_democtrans)
tab gwf_fail_subsregime gwf_democtrans

* Regime failures due to foreign intervention
tab gwf_fail_type
recode gwf_fail_type (7=1) (1 2 3 4 5 6 8 9=0), gen(gwf_interventionfail)
tab gwf_fail_type gwf_interventionfail

* Regime failures due to mass uprising
tab gwf_fail_type
recode gwf_fail_type (4=1) (1 2 3 5 6 7 8 9=0), gen(gwf_protestfail)
tab gwf_fail_type gwf_protestfail


* Descriptive Timeline of Foreign legions in Autocracies and Non-Autocracies
gen autoc=1 if latent_personalism!=.
replace autoc=0 if latent_personalism==. & year<=2010

preserve
gen case=1
collapse (sum) foreignlegion case, by(year autoc) 
gen fl_share_autoc=foreignlegion/case if autoc==1
gen fl_share_nonautoc=foreignlegion/case if autoc==0
collapse (sum) fl_share_autoc fl_share_nonautoc, by(year) 
twoway line  fl_share_autoc fl_share_nonautoc year if year<=2010, scheme(plotplain) legend(pos(6) cols(2) order(1 "Autocracies" 2 "Non-Autocracies")) xlabel(1945(5)2010) xtitle("")
graph export timetrends.pdf, as(pdf) replace 
restore
 
**************************************
** Analysis - Who uses legionaires? **
**************************************

* Descriptive
ttest fl_onset, by(autoc) unequal
ttest foreignlegion, by(autoc) unequal

graph box  latent_personalism, over(fl_onset, relabel(1 "No FL onset" 2 "FL onset")) ytitle("Personalism") scheme(tufte)
ttest latent_personalism, by(fl_onset) unequal


* main models, controls following Grasmeder paper
quietly logit fl_onset latent_personalism militaryshare ln_gdp_pc ln_pop intrastate mid_incid rivalry c.fl_years##c.fl_years##c.fl_years, vce(cluster ccode)
gen sample_fl=1 if e(sample)==1

est clear
eststo: logit fl_onset latent_personalism c.fl_years##c.fl_years##c.fl_years if sample_fl==1, vce(cluster ccode)
eststo: logit fl_onset latent_personalism militaryshare ln_gdp_pc ln_pop c.fl_years##c.fl_years##c.fl_years, vce(cluster ccode)
eststo: logit fl_onset latent_personalism militaryshare ln_gdp_pc ln_pop intrastate mid_incid rivalry c.fl_years##c.fl_years##c.fl_years, vce(cluster ccode)
esttab using "./main_dv_legions.tex", replace  ///
 b(3) se(3) label star(* 0.10 ** 0.05) ///
 booktabs alignment(D{.}{.}{-1}) ///
 title(Personalism and the Establishment of Foreign Legions in Autocracies \label{tab:main1})   ///
 addnotes("Dependent variable: Establishment of a foreign legion." "Cubic polynomials are included in models but omitted from presentation." "Standard errors clustered on the country in parentheses.") drop(fl_years c.fl_years#c.fl_years c.fl_years#c.fl_years#c.fl_years) ///
 coeflabels( latent_personalism "Personalism" militaryshare "Military Share" ln_gdp_pc "GDP per capita" ln_pop "Population" intrastate "Intrastate Conflict" mid_incid "Interstate Conflict" rivalry "Active Rivalries") ///
 scalars("ll Log Likelihood") aic nomtitles

* Results plot 
gen v2=latent_personalism
generate where = -0.001
generate pipe = "|"

logit fl_onset latent_personalism militaryshare ln_gdp_pc ln_pop intrastate mid_incid rivalry c.fl_years##c.fl_years##c.fl_years, vce(cluster ccode)
margins, at(latent_personalism=(0(0.025)1)) level(95) 
marginsplot, scheme(plotplain) xtitle("{it:Personalism}") ytitle("Legionnaire Recruitment Onset") recastci(rline) ciopts(lpattern(dash) lcolor(black)) plotopts(msymbol(none)) yline(0) name(g1, replace) aspect(1) title("") ///
addplot (scatter where v2 if e(sample),  ms(none) xlabel(0.0(0.1)1) ylabel(0.00(0.005)0.025) blcolor(gray) mlabel(pipe) mlabpos(0)) legend(off)
graph export g1_fl.pdf, as(pdf) replace 
 

**********************************************
** Analysis - Legionaires and Coup Attempts **
**********************************************
tab coupattempt foreignlegion if latent_personalism!=., column

* main models
quietly logit coupattempt foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop intrastate mid_incid c.att_years##c.att_years##c.att_years, vce(cluster ccode)
gen sample_ca=1 if e(sample)==1

est clear
eststo: logit coupattempt foreignlegion c.att_years##c.att_years##c.att_years if sample_ca==1, vce(cluster ccode)
eststo: logit coupattempt foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop c.att_years##c.att_years##c.att_years, vce(cluster ccode)
eststo: logit coupattempt foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop intrastate mid_incid c.att_years##c.att_years##c.att_years, vce(cluster ccode)
esttab using "./main_dv_coup.tex", replace  ///
 b(3) se(3) label star(* 0.10 ** 0.05) ///
 booktabs alignment(D{.}{.}{-1}) ///
 title(Foreign Legions and Coup Attempts in Autocracies \label{tab:main2})   ///
 addnotes("Dependent variable: Coup Attempt." "Cubic polynomials are included in models but omitted from presentation." "Standard errors clustered on the country in parentheses.") drop(att_years c.att_years#c.att_years c.att_years#c.att_years#c.att_years) ///
 coeflabels( latent_personalism "Personalism" militaryshare "Military Share" intrastate "Intrastate Conflict" mid_incid "Interstate Conflict" ln_gdp_pc "GDP per capita" ln_milex "Military Expenditures" diff_lngdppc "$\Delta$ GDP per capita" diff_lnmilex "$\Delta$ Military Expenditures" ln_pop "Population") ///
 scalars("ll Log Likelihood") aic nomtitles 

* Results Plot
logit coupattempt foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop intrastate mid_incid c.att_years##c.att_years##c.att_years, vce(cluster ccode)

margins, at(foreignlegion=(0(1)1)) level(95)
marginsplot, scheme(plotplain) recast(scatter) aspect(1) xtitle("{it:Foreign Legion}") title("Prob.: Coup Attempt") name(g2, replace) ytitle("") legend(off) ylabel(0.01(0.01)0.08) plotopts(msymbol(circle)) xlabel(0 "No" 1 "Yes") 


**********************************************
** Analysis - Legionaires and Mass Uprisings **
**********************************************
btscs renavco_nvc_onset year ccode, gen(renavco_years)

* set non-onset observations in the Renavco onset variable to missing instead of 0
replace renavco_nvc_onset=. if renavco_nvc==1 & renavco_nvc_onset==0

tab renavco_nvc_onset foreignlegion if latent_personalism!=., column

* main models
quietly logit renavco_nvc_onset foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop intrastate mid_incid c.renavco_years##c.renavco_years##c.renavco_years, vce(cluster ccode)
gen sample_nvc=1 if e(sample)==1

est clear
eststo: logit renavco_nvc_onset foreignlegion c.renavco_years##c.renavco_years##c.renavco_years if sample_nvc==1, vce(cluster ccode)
eststo: logit renavco_nvc_onset foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop c.renavco_years##c.renavco_years##c.renavco_years if sample_nvc==1, vce(cluster ccode)
eststo: logit renavco_nvc_onset foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop intrastate mid_incid c.renavco_years##c.renavco_years##c.renavco_years if sample_nvc==1, vce(cluster ccode)
esttab using "./main_dv_nvc.tex", replace  ///
 b(3) se(3) label star(* 0.10 ** 0.05) ///
 booktabs alignment(D{.}{.}{-1}) ///
 title(Foreign Legions and Mass Uprisings in Autocracies \label{tab:main2})   ///
 addnotes("Dependent variable: Mass Uprising Onset." "Cubic polynomials are included in models but omitted from presentation." "Standard errors clustered on the country in parentheses.") drop(renavco_years c.renavco_years#c.renavco_years c.renavco_years#c.renavco_years#c.renavco_years) ///
 coeflabels( latent_personalism "Personalism" militaryshare "Military Share" intrastate "Intrastate Conflict" mid_incid "Interstate Conflict" ln_gdp_pc "GDP per capita" ln_milex "Military Expenditures" diff_lngdppc "$\Delta$ GDP per capita" diff_lnmilex "$\Delta$ Military Expenditures" ln_pop "Population") ///
 scalars("ll Log Likelihood") aic nomtitles 
 
 * Results Plot
logit renavco_nvc_onset foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop intrastate mid_incid c.renavco_years##c.renavco_years##c.renavco_years if sample_nvc==1, vce(cluster ccode)

margins, at(foreignlegion=(0(1)1)) level(95)
marginsplot, scheme(plotplain) recast(scatter) aspect(1) xtitle("{it:Foreign Legion}") title("Prob.: Mass Uprising") name(g3, replace) ytitle("") legend(off) ylabel(0.01(0.01)0.08) plotopts(msymbol(circle)) xlabel(0 "No" 1 "Yes")

graph combine g3 g2, ycommon scheme(plotplain)
graph export g23_combined.pdf, as(pdf) replace


* Combined results table coup attempts and muass uprisings
est clear
eststo: logit coupattempt foreignlegion c.att_years##c.att_years##c.att_years if sample_ca==1, vce(cluster ccode)
eststo: logit coupattempt foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop c.att_years##c.att_years##c.att_years, vce(cluster ccode)
eststo: logit coupattempt foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop intrastate mid_incid c.att_years##c.att_years##c.att_years, vce(cluster ccode)
eststo: logit renavco_nvc_onset foreignlegion c.renavco_years##c.renavco_years##c.renavco_years if sample_nvc==1, vce(cluster ccode)
eststo: logit renavco_nvc_onset foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop c.renavco_years##c.renavco_years##c.renavco_years if sample_nvc==1, vce(cluster ccode)
eststo: logit renavco_nvc_onset foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop intrastate mid_incid c.renavco_years##c.renavco_years##c.renavco_years if sample_nvc==1, vce(cluster ccode)
esttab using "./main_dv_combined.tex", replace  ///
 b(3) se(3) label star(* 0.10 ** 0.05) ///
 booktabs alignment(D{.}{.}{-1}) ///
 title(Foreign Legions and Regime Challenges in Autocracies \label{tab:main2})   ///
 addnotes("Dependent variables: Coup Attempt." "Cubic polynomials are included in models but omitted from presentation." "Standard errors clustered on the country in parentheses.") drop(att_years c.att_years#c.att_years c.att_years#c.att_years#c.att_years renavco_years c.renavco_years#c.renavco_years c.renavco_years#c.renavco_years#c.renavco_years) ///
 coeflabels( latent_personalism "Personalism" militaryshare "Military Share" intrastate "Intrastate Conflict" mid_incid "Interstate Conflict" ln_gdp_pc "GDP per capita" ln_milex "Military Spending" diff_lngdppc "$\Delta$ GDP per capita" diff_lnmilex "$\Delta$ Military Spending" ln_pop "Population") ///
 scalars("ll Log Likelihood") aic nomtitles

* Combined results figure -> include all six models here
logit coupattempt foreignlegion c.att_years##c.att_years##c.att_years if sample_ca==1, vce(cluster ccode)
margins, dydx(foreignlegion) level(95) post
estimates store ca1
logit coupattempt foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop c.att_years##c.att_years##c.att_years, vce(cluster ccode)
margins, dydx(foreignlegion) level(95) post
estimates store ca2
logit coupattempt foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop intrastate mid_incid c.att_years##c.att_years##c.att_years, vce(cluster ccode)
margins, dydx(foreignlegion) level(95) post
estimates store ca3
logit renavco_nvc_onset foreignlegion c.renavco_years##c.renavco_years##c.renavco_years if sample_nvc==1, vce(cluster ccode)
margins, dydx(foreignlegion) level(95) post
estimates store mu1
logit renavco_nvc_onset foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop c.renavco_years##c.renavco_years##c.renavco_years if sample_nvc==1, vce(cluster ccode)
margins, dydx(foreignlegion) level(95) post
estimates store mu2
logit renavco_nvc_onset foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop intrastate mid_incid c.renavco_years##c.renavco_years##c.renavco_years if sample_nvc==1, vce(cluster ccode)
margins, dydx(foreignlegion) level(95) post
estimates store mu3

coefplot (ca1, label(Model 4) msymbol(O)) (ca2, label(Model 5) msymbol(O)) (ca3, label(Model 6) msymbol(O)) (mu1, label(Model 7) msymbol(D)) (mu2, label(Model 8)  msymbol(D)) (mu3, label(Model 9)  msymbol(D)), xline(0) scheme(plotplainblind)  xtitle("Change in Probability of Regime Challenge") aspectratio(1) yscale(noline) levels(95 90) legend(position(3) cols(1) colgap(*.3) size(*.75)) ylabel(0.62 "Coup Attempt" 1.05 "Mass Uprising", noticks) name(fig_new, replace)
graph export g23_combined.pdf, as(pdf) replace

* Robustness checks: RE logit, rare events logit, omitting personalization outliers (outliers=top 10% values), excluding paramilitary indicator from the latent personalism measure,  MID and UCDP duration instead of incidence, controlling for: milex, conscription, colonial origin, excluded ethnic groups, accounting for time trends

* RE logit
est clear
eststo: xtlogit fl_onset latent_personalism militaryshare ln_gdp_pc ln_pop intrastate rivalry mid_incid c.fl_years##c.fl_years##c.fl_years, vce(cluster ccode) re
eststo: xtlogit coupattempt foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate c.att_years##c.att_years##c.att_years, vce(cluster ccode) re
eststo: xtlogit renavco_nvc_onset foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop intrastate mid_incid c.renavco_years##c.renavco_years##c.renavco_years if sample_nvc==1, vce(cluster ccode) re
esttab using "./rob_randomeffects.tex", replace  ///
 b(3) se(3) label star(* 0.10 ** 0.05) ///
 booktabs alignment(D{.}{.}{-1}) ///
 title(Random Effects Models \label{tab:app1})   ///
 addnotes("Cubic polynomials are included in models but omitted from presentation." "Standard errors clustered on the country in parentheses.") drop(fl_years c.fl_years#c.fl_years c.fl_years#c.fl_years#c.fl_years att_years c.att_years#c.att_years c.att_years#c.att_years#c.att_years renavco_years c.renavco_years#c.renavco_years c.renavco_years#c.renavco_years#c.renavco_years) coeflabels( latent_personalism "Personalism" militaryshare "Military Share" ln_gdp_pc "GDP per capita" ln_pop "Population" intrastate "Intrastate Conflict" mid_incid "Interstate Conflict" rivalry "Active Rivalries" ln_milex "Military Spending" diff_lngdppc "$\Delta$ GDP per capita" diff_lnmilex "$\Delta$ Military Spending") scalars("ll Log Likelihood") aic mtitles("DV: Foreign Legion Establishment" "DV: Coup Attempt" "DV: Mass Uprising Onset")

* PMLE logit 
gen fl_years_sq=fl_years*fl_years
gen fl_years_cb=fl_years*fl_years_sq
gen att_years_sq=att_years*att_years
gen att_years_cb=att_years*att_years_sq
gen renavco_years_sq=renavco_years*renavco_years
gen renavco_years_cb=renavco_years*renavco_years_sq
est clear
eststo: firthlogit fl_onset latent_personalism militaryshare ln_gdp_pc ln_pop intrastate rivalry mid_incid fl_years fl_years_sq fl_years_cb
eststo: firthlogit coupattempt foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate att_years att_years_sq att_years_cb
eststo: firthlogit renavco_nvc_onset foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop intrastate mid_incid renavco_years renavco_years_sq renavco_years_cb
esttab using "./rob_firth.tex", replace  ///
 b(3) se(3) label star(* 0.10 ** 0.05) ///
 booktabs alignment(D{.}{.}{-1}) ///
 title(Penalized Maximum Likelihood Logit Models \label{tab:app2})   ///
 addnotes("Cubic polynomials are included in models but omitted from presentation." "Standard errors clustered on the country in parentheses.") drop(fl_years fl_years_sq fl_years_cb att_years att_years_sq att_years_cb renavco_years renavco_years_sq renavco_years_cb) coeflabels( latent_personalism "Personalism" militaryshare "Military Share" ln_gdp_pc "GDP per capita" ln_pop "Population" intrastate "Intrastate Conflict" mid_incid "Interstate Conflict" rivalry "Active Rivalries" ln_milex "Military Spending" diff_lngdppc "$\Delta$ GDP per capita" diff_lnmilex "$\Delta$ Military Spending") scalars("ll Log Likelihood") aic mtitles("DV: Foreign Legion Establishment" "DV: Coup Attempt" "DV: Mass Uprising Onset")

* Time Trends
est clear
eststo: logit fl_onset latent_personalism militaryshare ln_gdp_pc ln_pop intrastate rivalry mid_incid c.year##c.year##c.year c.fl_years##c.fl_years##c.fl_years, vce(cluster ccode)
eststo: logit coupattempt foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid  intrastate c.year##c.year##c.year c.att_years##c.att_years##c.att_years, vce(cluster ccode)
eststo: logit renavco_nvc_onset foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop intrastate mid_incid c.year##c.year##c.year c.renavco_years##c.renavco_years##c.renavco_years, vce(cluster ccode)
esttab using "./rob_timetrends.tex", replace  ///
 b(3) se(3) label star(* 0.10 ** 0.05) ///
 booktabs alignment(D{.}{.}{-1}) ///
 title(models with Time trends \label{tab:app3})   ///
 addnotes("Cubic polynomials are included in models but omitted from presentation." "Standard errors clustered on the country in parentheses.") drop(fl_years c.fl_years#c.fl_years c.fl_years#c.fl_years#c.fl_years att_years c.att_years#c.att_years c.att_years#c.att_years#c.att_years renavco_years c.renavco_years#c.renavco_years c.renavco_years#c.renavco_years#c.renavco_years year c.year#c.year c.year#c.year#c.year) coeflabels( latent_personalism "Personalism" militaryshare "Military Share" ln_gdp_pc "GDP per capita" ln_pop "Population" intrastate "Intrastate Conflict" mid_incid "Interstate Conflict" rivalry "Active Rivalries" ln_milex "Military Spending" diff_lngdppc "$\Delta$ GDP per capita" diff_lnmilex "$\Delta$ Military Spending") scalars("ll Log Likelihood") aic mtitles("DV: Foreign Legion Establishment" "DV: Coup Attempt" "DV: Mass Uprising Onset")
 
* personalism & foreign legions: Drop outlier and omit security force creation 
est clear
eststo: logit fl_onset latent_personalism militaryshare ln_gdp_pc ln_pop intrastate rivalry mid_incid c.fl_years##c.fl_years##c.fl_years if latent_personalism<=0.7815722, vce(cluster ccode)
eststo: logit fl_onset latent_personalism_noparam militaryshare ln_gdp_pc ln_pop intrastate mid_incid rivalry c.fl_years##c.fl_years##c.fl_years, vce(cluster ccode)
esttab using "./rob_legions_addit.tex", replace  ///
 b(3) se(3) label star(* 0.10 ** 0.05) ///
 booktabs alignment(D{.}{.}{-1}) ///
 title(Dropping Personalism Outlier and Restricting the Personalism Measure \label{tab:app4})   ///
 addnotes("Cubic polynomials are included in models but omitted from presentation." "Standard errors clustered on the country in parentheses.") drop(fl_years c.fl_years#c.fl_years c.fl_years#c.fl_years#c.fl_years) coeflabels( latent_personalism "Personalism" latent_personalism_noparam "Personalism - Restricted" militaryshare "Military Share" ln_gdp_pc "GDP per capita" ln_pop "Population" intrastate "Intrastate Conflict" mid_incid "Interstate Conflict" rivalry "Active Rivalries") scalars("ll Log Likelihood") aic mtitles("DV: Foreign Legion Establishment" "DV: Foreign Legion Establishment")
 
* Legionnaires and Repression during Mass Uprisings:
quietly reghdfe repression_latvar foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop renavco_years renavco_nvc_onset_lregcnt if renavco_nvc==1, absorb(ccode year) vce(cluster ccode)
gen sample_repall=1 if e(sample)==1
quietly reghdfe repression_latvar foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop renavco_years renavco_nvc_onset_lregcnt if renavco_nvc_onset==1, absorb(ccode year) vce(cluster ccode)
gen sample_reponset=1 if e(sample)==1

est clear
eststo: reghdfe repression_latvar foreignlegion if sample_repall==1, absorb(ccode year) vce(cluster ccode)
eststo: reghdfe repression_latvar foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop  if sample_repall==1, absorb(ccode year) vce(cluster ccode)
eststo: reghdfe repression_latvar foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop renavco_years renavco_nvc_onset_lregcnt  if sample_repall==1, absorb(ccode year) vce(cluster ccode)
eststo: reghdfe repression_latvar foreignlegion if sample_reponset==1, absorb(ccode year) vce(cluster ccode)
eststo: reghdfe repression_latvar foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop  if sample_reponset==1, absorb(ccode year) vce(cluster ccode)
eststo: reghdfe repression_latvar foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop renavco_years renavco_nvc_onset_lregcnt  if sample_reponset==1, absorb(ccode year) vce(cluster ccode) 
esttab using "./rob_uprising_repress.tex", replace  ///
b(3) se(3) label star(* 0.10 ** 0.05) ///
booktabs alignment(D{.}{.}{-1}) ///
title(Foreign Legions and Repression during Mass Uprising \label{tab:app5})   ///
addnotes("Two-way fixed effects models." "Standard errors clustered on the country in parentheses.") coeflabels( latent_personalism "Personalism" militaryshare "Military Share" ln_gdp_pc "GDP per capita" ln_pop "Population" intrastate "Intrastate Conflict" mid_incid "Interstate Conflict" rivalry "Active Rivalries" ln_milex "Military Spending" diff_lngdppc "$\Delta$ GDP per capita" diff_lnmilex "$\Delta$ Military Spending" renavco_years "Time since Last Uprising" renavco_nvc_onset_lregcnt "Neighbor Uprisings") aic nomtitles

* Check coup success and violence
tab success if sample_ca==1
tab howviolent if sample_ca==1
tab violent if sample_ca==1

btscs success year ccode, gen(succ_years)
btscs howviolent year ccode, gen(howv_years)
btscs violent year ccode, gen(viol_years)  

heckprob violent foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex mid_incid intrastate c.viol_years##c.viol_years##c.viol_years if sample_ca==1, vce(cluster ccode) select(coupattempt=foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate c.att_years##c.att_years##c.att_years)

heckoprobit howviolent foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex mid_incid intrastate c.viol_years##c.viol_years##c.viol_years if sample_ca==1, vce(cluster ccode) select(coupattempt=foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate c.att_years##c.att_years##c.att_years)

heckprob success foreignlegion c.succ_years##c.succ_years##c.succ_years if sample_ca==1, vce(cluster ccode) select(coupattempt=foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate c.att_years##c.att_years##c.att_years)

heckprob success foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex c.succ_years##c.succ_years##c.succ_years if sample_ca==1, vce(cluster ccode) select(coupattempt=foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate c.att_years##c.att_years##c.att_years)

heckprob success foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate c.succ_years##c.succ_years##c.succ_years if sample_ca==1, vce(cluster ccode) select(coupattempt=foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate c.att_years##c.att_years##c.att_years)

est clear
eststo:heckprob success foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex mid_incid intrastate c.succ_years##c.succ_years##c.succ_years if sample_ca==1, vce(cluster ccode) select(coupattempt=foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate c.att_years##c.att_years##c.att_years)
esttab using "./rob_coupsuc.tex", replace  ///
 b(3) se(3) label star(* 0.10 ** 0.05) ///
 booktabs alignment(D{.}{.}{-1}) ///
 title(Coup Success Selection Model \label{tab:app14})   ///
 addnotes("Cubic polynomials are included in models but omitted from presentation." "Standard errors clustered on the country in parentheses.") drop( att_years c.att_years#c.att_years c.att_years#c.att_years#c.att_years succ_years c.succ_years#c.succ_years c.succ_years#c.succ_years#c.succ_years athrho) coeflabels( latent_personalism "Personalism" militaryshare "Military Share" ln_gdp_pc "GDP per capita" ln_pop "Population" intrastate "Intrastate Conflict" mid_incid "Interstate Conflict" rivalry "Active Rivalries" ln_milex "Military Spending" diff_lngdppc "$\Delta$ GDP per capita" diff_lnmilex "$\Delta$ Military Spending" renavco_nvc "Mass Uprising" coupattempt "Coup Attempt" ) scalars("ll Log Likelihood") aic unstack  mtitles("DV: Coup Success" "DV: Coup Attempt") 
 
* Interdependence between Coup Attempts and mass uprisings
gen regimechallenge=0 if coupattempt==0 & renavco_nvc_onset==0
replace regimechallenge=1 if coupattempt==1 & renavco_nvc_onset==0
replace regimechallenge=2 if coupattempt==0 & renavco_nvc_onset==1
replace regimechallenge=3 if coupattempt==1 & renavco_nvc_onset==1

est clear
eststo: biprobit coupattempt renavco_nvc_onset foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop intrastate mid_incid c.att_years##c.att_years##c.att_years c.renavco_years##c.renavco_years##c.renavco_years , vce(cluster ccode)
eststo: logit coupattempt foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop intrastate mid_incid renavco_nvc c.att_years##c.att_years##c.att_years, vce(cluster ccode)
eststo: logit renavco_nvc_onset foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate coupattempt c.renavco_years##c.renavco_years##c.renavco_years, vce(cluster ccode)
esttab using "./rob_interdep.tex", replace  ///
 b(3) se(3) label star(* 0.10 ** 0.05) ///
 booktabs alignment(D{.}{.}{-1}) ///
 title(Modelling Coup Attems and Mass Uprisings together \label{tab:app6})   ///
 addnotes("Cubic polynomials are included in models but omitted from presentation." "Standard errors clustered on the country in parentheses.") drop( att_years c.att_years#c.att_years c.att_years#c.att_years#c.att_years renavco_years c.renavco_years#c.renavco_years c.renavco_years#c.renavco_years#c.renavco_years athrho) coeflabels( latent_personalism "Personalism" militaryshare "Military Share" ln_gdp_pc "GDP per capita" ln_pop "Population" intrastate "Intrastate Conflict" mid_incid "Interstate Conflict" rivalry "Active Rivalries" ln_milex "Military Spending" diff_lngdppc "$\Delta$ GDP per capita" diff_lnmilex "$\Delta$ Military Spending" renavco_nvc "Mass Uprising" coupattempt "Coup Attempt" ) scalars("ll Log Likelihood") aic mtitles("DV: Coup Attempt" "DV: Mass Uprising Onset" "DV: Coup Attempt" "DV: Mass Uprising Onset") unstack
 

* Controlling for Conflict Duration 
est clear
eststo: logit fl_onset latent_personalism militaryshare ln_gdp_pc ln_pop intra_dur  rivalry mid_dur c.fl_years##c.fl_years##c.fl_years, vce(cluster ccode)
eststo: logit coupattempt foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_dur intra_dur c.att_years##c.att_years##c.att_years, vce(cluster ccode)
eststo: logit renavco_nvc_onset foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_dur intra_dur c.renavco_years##c.renavco_years##c.renavco_years, vce(cluster ccode)
esttab using "./rob_confdur.tex", replace  ///
 b(3) se(3) label star(* 0.10 ** 0.05) ///
 booktabs alignment(D{.}{.}{-1}) ///
 title(Controlling for Conflict Duration \label{tab:app7})   ///
 addnotes("Cubic polynomials are included in models but omitted from presentation." "Standard errors clustered on the country in parentheses.") drop(fl_years c.fl_years#c.fl_years c.fl_years#c.fl_years#c.fl_years att_years c.att_years#c.att_years c.att_years#c.att_years#c.att_years renavco_years c.renavco_years#c.renavco_years c.renavco_years#c.renavco_years#c.renavco_years) coeflabels( latent_personalism "Personalism" militaryshare "Military Share" ln_gdp_pc "GDP per capita" ln_pop "Population" intra_dur "Intrastate Conflict Duration" mid_dur "Interstate Conflict Duration" rivalry "Active Rivalries" ln_milex "Military Spending" diff_lngdppc "$\Delta$ GDP per capita" diff_lnmilex "$\Delta$ Military Spending") scalars("ll Log Likelihood") aic mtitles("DV: Foreign Legion Establishment" "DV: Coup Attempt" "DV: Mass Uprising Onset")


*Further controls Legion onset
est clear
eststo: logit fl_onset latent_personalism militaryshare ln_gdp_pc ln_pop intrastate rivalry mid_incid ln_milex c.fl_years##c.fl_years##c.fl_years, vce(cluster ccode)
eststo: logit fl_onset latent_personalism militaryshare ln_gdp_pc ln_pop intrastate rivalry mid_incid draft_binary c.fl_years##c.fl_years##c.fl_years, vce(cluster ccode)
eststo: logit fl_onset latent_personalism militaryshare ln_gdp_pc ln_pop intrastate rivalry mid_incid col_uk col_fr c.fl_years##c.fl_years##c.fl_years, vce(cluster ccode)
eststo: logit fl_onset latent_personalism militaryshare ln_gdp_pc ln_pop intrastate rivalry mid_incid gwf_military c.fl_years##c.fl_years##c.fl_years, vce(cluster ccode)
eststo: logit fl_onset latent_personalism militaryshare ln_gdp_pc ln_pop intrastate rivalry mid_incid gwf_leader_duration c.fl_years##c.fl_years##c.fl_years, vce(cluster ccode)
esttab using "./rob_legions_controls1.tex", replace  ///
 b(3) se(3) label star(* 0.10 ** 0.05) ///
 booktabs alignment(D{.}{.}{-1}) ///
 title(Personalism and the Establishment of Foreign Legions in Autocracies -- Additional Controls I \label{tab:main1})   ///
 addnotes("Dependent variable: Establishment of a foreign legion." "Cubic polynomials are included in models but omitted from presentation." "Standard errors clustered on the country in parentheses.") drop(fl_years c.fl_years#c.fl_years c.fl_years#c.fl_years#c.fl_years) coeflabels( latent_personalism "Personalism" militaryshare "Military Share" ln_gdp_pc "GDP per capita" ln_pop "Population" intrastate "Intrastate Conflict" mid_incid "Interstate Conflict" rivalry "Active Rivalries" ln_milex "Military Expenditures" draft_binary "Conscription" col_uk "British Colony" col_fr "French Colony" legippop "Excluded Ethnic Groups" ln_upop "Urban Population" renavco_nvc "Regional Mass Uprising" gwf_leader_duration "Leader Tenure") scalars("ll Log Likelihood") aic nomtitles

est clear
eststo: logit fl_onset latent_personalism militaryshare ln_gdp_pc ln_pop intrastate rivalry mid_incid legippop c.fl_years##c.fl_years##c.fl_years, vce(cluster ccode)
eststo: logit fl_onset latent_personalism militaryshare ln_gdp_pc ln_pop intrastate rivalry mid_incid ln_upop c.fl_years##c.fl_years##c.fl_years, vce(cluster ccode)
eststo: logit fl_onset latent_personalism militaryshare ln_gdp_pc ln_pop intrastate rivalry mid_incid l.reg_coups c.fl_years##c.fl_years##c.fl_years, vce(cluster ccode)
eststo: logit fl_onset latent_personalism militaryshare ln_gdp_pc ln_pop intrastate rivalry mid_incid l.renavco_nvc_onset_lregcnt c.fl_years##c.fl_years##c.fl_years, vce(cluster ccode)
eststo: logit fl_onset latent_personalism militaryshare ln_gdp_pc ln_pop intrastate rivalry mid_incid l.renavco_nvc c.fl_years##c.fl_years##c.fl_years, vce(cluster ccode)
eststo: logit fl_onset latent_personalism militaryshare ln_gdp_pc ln_pop intrastate rivalry mid_incid l.coupattempt c.fl_years##c.fl_years##c.fl_years, vce(cluster ccode)
esttab using "./rob_legions_controls2.tex", replace  ///
 b(3) se(3) label star(* 0.10 ** 0.05) ///
 booktabs alignment(D{.}{.}{-1}) ///
 title(Personalism and the Establishment of Foreign Legions in Autocracies -- Additional Controls II \label{tab:main1})   ///
 addnotes("Dependent variable: Establishment of a foreign legion." "Cubic polynomials are included in models but omitted from presentation." "Standard errors clustered on the country in parentheses.") drop(fl_years c.fl_years#c.fl_years c.fl_years#c.fl_years#c.fl_years) coeflabels( latent_personalism "Personalism" militaryshare "Military Share" ln_gdp_pc "GDP per capita" ln_pop "Population" intrastate "Intrastate Conflict" mid_incid "Interstate Conflict" rivalry "Active Rivalries" ln_milex "Military Expenditures" draft_binary "Conscription" col_uk "British Colony" col_fr "French Colony" legippop "Excluded Ethnic Groups" ln_upop "Urban Population" renavco_nvc "Regional Mass Uprising" reg_coups "Regional Coup Attempts") scalars("ll Log Likelihood") aic nomtitles

*Further controls Coup Attempts
est clear
eststo: logit coupattempt foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate rivalry c.att_years##c.att_years##c.att_years, vce(cluster ccode)
eststo: logit coupattempt foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate draft_binary c.att_years##c.att_years##c.att_years, vce(cluster ccode)
eststo: logit coupattempt foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate col_uk col_fr c.att_years##c.att_years##c.att_years, vce(cluster ccode)
eststo: logit coupattempt foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate legippop c.att_years##c.att_years##c.att_years, vce(cluster ccode)
eststo: logit coupattempt foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid  intrastate gwf_leader_duration c.att_years##c.att_years##c.att_years, vce(cluster ccode)
esttab using "./rob_coup_controls1.tex", replace  ///
b(3) se(3) label star(* 0.10 ** 0.05) ///
booktabs alignment(D{.}{.}{-1}) ///
title(Foreign Legions and Coup Attempts in Autocracies -- Additional Controls I \label{tab:main2})   ///
addnotes("Dependent variable: Coup Attempt." "Cubic polynomials are included in models but omitted from presentation." "Standard errors clustered on the country in parentheses.") drop(att_years c.att_years#c.att_years c.att_years#c.att_years#c.att_years) coeflabels( latent_personalism "Personalism" militaryshare "Military Share" intrastate "Intrastate Conflict" mid_incid "Interstate Conflict" ln_gdp_pc "GDP per capita" ln_milex "Military Expenditures" diff_lngdppc "$\Delta$ GDP per capita" diff_lnmilex "$\Delta$ Military Expenditures"ln_pop "Population" rivalry "Rivalry" draft_binary "Conscription" col_uk "British Colony"col_fr "French Colony" legippop "Excluded Ethnic Groups" ln_upop "Urban Population" renavco_nvc "Mass Uprising" latent_personalism_noparam "Personalism - Restricted" gwf_leader_duration "Leader Tenure") scalars("ll Log Likelihood") aic nomtitles 

est clear
eststo: logit coupattempt foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate ln_upop c.att_years##c.att_years##c.att_years, vce(cluster ccode)
eststo: logit coupattempt foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate l.reg_coups c.att_years##c.att_years##c.att_years, vce(cluster ccode)
eststo: logit coupattempt foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop intrastate mid_incid l.renavco_nvc_onset_lregcnt c.att_years##c.att_years##c.att_years, vce(cluster ccode)
eststo: logit coupattempt foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop intrastate mid_incid gwf_military c.att_years##c.att_years##c.att_years, vce(cluster ccode)
eststo: logit coupattempt foreignlegion latent_personalism_noparam militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate c.att_years##c.att_years##c.att_years, vce(cluster ccode)
esttab using "./rob_coup_controls2.tex", replace  ///
b(3) se(3) label star(* 0.10 ** 0.05) ///
booktabs alignment(D{.}{.}{-1}) ///
title(Foreign Legions and Coup Attempts in Autocracies -- Additional Controls II \label{tab:main2})   ///
addnotes("Dependent variable: Coup Attempt." "Cubic polynomials are included in models but omitted from presentation." "Standard errors clustered on the country in parentheses.") drop(att_years c.att_years#c.att_years c.att_years#c.att_years#c.att_years) coeflabels( latent_personalism "Personalism" militaryshare "Military Share" intrastate "Intrastate Conflict" mid_incid "Interstate Conflict" ln_gdp_pc "GDP per capita" ln_milex "Military Expenditures" diff_lngdppc "$\Delta$ GDP per capita" diff_lnmilex "$\Delta$ Military Expenditures"ln_pop "Population" rivalry "Rivalry" draft_binary "Conscription" col_uk "British Colony"col_fr "French Colony" legippop "Excluded Ethnic Groups" ln_upop "Urban Population" renavco_nvc "Mass Uprising" latent_personalism_noparam "Personalism - Restricted" reg_coups "Regional Coup Attempts") scalars("ll Log Likelihood") aic nomtitles 

*Further controls Mass Uprisings
est clear
eststo: logit renavco_nvc_onset foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate rivalry c.renavco_years##c.renavco_years##c.renavco_years, vce(cluster ccode)
eststo: logit renavco_nvc_onset foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate draft_binary c.renavco_years##c.renavco_years##c.renavco_years, vce(cluster ccode)
eststo: logit renavco_nvc_onset foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate col_uk col_fr c.renavco_years##c.renavco_years##c.renavco_years, vce(cluster ccode)
eststo: logit renavco_nvc_onset foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate legippop c.renavco_years##c.renavco_years##c.renavco_years, vce(cluster ccode)
eststo: logit renavco_nvc_onset foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop intrastate mid_incid gwf_leader_duration c.renavco_years##c.renavco_years##c.renavco_years, vce(cluster ccode)
esttab using "./rob_nvc_controls1.tex", replace  ///
b(3) se(3) label star(* 0.10 ** 0.05) ///
booktabs alignment(D{.}{.}{-1}) ///
title(Foreign Legions and Mass Uprisings in Autocracies -- Additional Controls I \label{tab:main2})   ///
addnotes("Dependent variable: Coup Attempt." "Cubic polynomials are included in models but omitted from presentation." "Standard errors clustered on the country in parentheses.") drop(renavco_years c.renavco_years#c.renavco_years c.renavco_years#c.renavco_years#c.renavco_years) coeflabels( latent_personalism "Personalism" militaryshare "Military Share" intrastate "Intrastate Conflict" mid_incid "Interstate Conflict" ln_gdp_pc "GDP per capita" ln_milex "Military Expenditures" diff_lngdppc "$\Delta$ GDP per capita" diff_lnmilex "$\Delta$ Military Expenditures"ln_pop "Population" rivalry "Rivalry" draft_binary "Conscription" col_uk "British Colony"col_fr "French Colony" legippop "Excluded Ethnic Groups" ln_upop "Urban Population" latent_personalism_noparam "Personalism - Restricted" gwf_leader_duration "Leader Tenure") scalars("ll Log Likelihood") aic nomtitles 

est clear
eststo: logit renavco_nvc_onset foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate ln_upop c.renavco_years##c.renavco_years##c.renavco_years, vce(cluster ccode)
eststo: logit renavco_nvc_onset foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop intrastate mid_incid l.reg_coups c.renavco_years##c.renavco_years##c.renavco_years, vce(cluster ccode)
eststo: logit renavco_nvc_onset foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate l.renavco_nvc_onset_lregcnt c.renavco_years##c.renavco_years##c.renavco_years, vce(cluster ccode)
eststo: logit renavco_nvc_onset foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate gwf_military c.renavco_years##c.renavco_years##c.renavco_years, vce(cluster ccode)
eststo: logit renavco_nvc_onset foreignlegion latent_personalism_noparam militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop mid_incid intrastate c.renavco_years##c.renavco_years##c.renavco_years, vce(cluster ccode)
esttab using "./rob_nvc_controls2.tex", replace  ///
b(3) se(3) label star(* 0.10 ** 0.05) ///
booktabs alignment(D{.}{.}{-1}) ///
title(Foreign Legions and Mass Uprisings in Autocracies -- Additional Controls II \label{tab:main2})   ///
addnotes("Dependent variable: Coup Attempt." "Cubic polynomials are included in models but omitted from presentation." "Standard errors clustered on the country in parentheses.") drop(renavco_years c.renavco_years#c.renavco_years c.renavco_years#c.renavco_years#c.renavco_years) coeflabels( latent_personalism "Personalism" militaryshare "Military Share" intrastate "Intrastate Conflict" mid_incid "Interstate Conflict" ln_gdp_pc "GDP per capita" ln_milex "Military Expenditures" diff_lngdppc "$\Delta$ GDP per capita" diff_lnmilex "$\Delta$ Military Expenditures"ln_pop "Population" rivalry "Rivalry" draft_binary "Conscription" col_uk "British Colony"col_fr "French Colony" legippop "Excluded Ethnic Groups" ln_upop "Urban Population" latent_personalism_noparam "Personalism - Restricted" L.reg_coups "Regional Coup Attempts") scalars("ll Log Likelihood") aic nomtitles 

* A Summary Statistics Table
sum fl_onset coupattempt renavco_nvc_onset latent_personalism foreignlegion militaryshare ln_gdp_pc ln_pop intrastate rivalry mid_incid ln_milex diff_lngdppc diff_lnmilex latent_personalism_noparam success renavco_nvc intra_dur mid_dur draft_binary col_uk col_fr gwf_military legippop ln_upop l.renavco_nvc_onset_lregcnt if sample_ca==1

gen bla=l.renavco_nvc_onset_lregcnt
gen bla2=l.reg_coups
 
est clear
eststo: estpost sum fl_onset coupattempt renavco_nvc_onset latent_personalism foreignlegion militaryshare ln_gdp_pc ln_pop intrastate rivalry mid_incid ln_milex diff_lngdppc diff_lnmilex latent_personalism_noparam renavco_nvc intra_dur mid_dur draft_binary col_uk col_fr gwf_leader_duration gwf_military legippop ln_upop bla bla2 if sample_ca==1
esttab using "./summary_stats.tex", replace cells("count mean(fmt(3)) sd(fmt(3)) min(fmt(3)) max(fmt(3))") nodepvar label b(3)

est clear
eststo: estpost sum repression_latvar if sample_repall==1
esttab using "./summary_stats2.tex", replace cells("count mean(fmt(3)) sd(fmt(3)) min(fmt(3)) max(fmt(3))") nodepvar label b(3)
est clear
eststo: estpost sum repression_latvar if sample_reponset==1
esttab using "./summary_stats2.tex", append cells("count mean(fmt(3)) sd(fmt(3)) min(fmt(3)) max(fmt(3))") nodepvar label b(3)


* Foreign removal as DV
btscs gwf_interventionfail year ccode, gen(intervenfail_years)

logit gwf_interventionfail foreignlegion c.intervenfail_years##c.intervenfail_years##c.intervenfail_years, vce(cluster ccode)
logit gwf_interventionfail foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop intrastate mid_incid c.intervenfail_years##c.intervenfail_years##c.intervenfail_years, vce(cluster ccode)

gen intervenfail_years_sq=intervenfail_years*intervenfail_years
gen intervenfail_years_cb=intervenfail_years*intervenfail_years_sq
est clear
eststo: firthlogit gwf_interventionfail foreignlegion intervenfail_years intervenfail_years_sq intervenfail_years_cb
eststo: firthlogit gwf_interventionfail foreignlegion latent_personalism militaryshare ln_gdp_pc ln_milex diff_lngdppc diff_lnmilex ln_pop intrastate mid_incid intervenfail_years intervenfail_years_sq intervenfail_years_cb
esttab using "./rob_intervention.tex", replace  ///
 b(3) se(3) label star(* 0.10 ** 0.05) ///
 booktabs alignment(D{.}{.}{-1}) ///
 title(Penalized Maximum Likelihood Logit Models \label{tab:app25})   ///
 addnotes("Cubic polynomials are included in models but omitted from presentation." "Standard errors clustered on the country in parentheses.") drop(intervenfail_years intervenfail_years_sq intervenfail_years_cb) coeflabels( latent_personalism "Personalism" militaryshare "Military Share" ln_gdp_pc "GDP per capita" ln_pop "Population" intrastate "Intrastate Conflict" mid_incid "Interstate Conflict" rivalry "Active Rivalries" ln_milex "Military Spending" diff_lngdppc "$\Delta$ GDP per capita" diff_lnmilex "$\Delta$ Military Spending") scalars("ll Log Likelihood") aic mtitles("DV: Foreign Intervention Removal" "DV: Foreign Intervention Removal")